<?php
/**
 * Smarty plugin
 * @package Smarty
 * @subpackage plugins
 */


/**
 * Smarty plugin
 *
 * Type:     modifier
 * Name:   links
 * Date:     Dec. 3, 2008
 * Purpose:  convert text links to clickable links with _blank targets
 * Input:
 *         - contents = contents to parse for text links
 * Example:  {$string|links}
 * @link http://smarty.php.net/manual/en/language.modifier.links.php
 *          links (Smarty online manual)
 * @version  1.0
 * @author   Tai Sheppard <tai at taisheppard dot com>
 * @param string
 * @return string
 */
function smarty_modifier_links($string)
{
    $string = html_entity_decode($string);
	$string = str_replace('</a>', '', $string);
	$string = preg_replace('/<a[^>]+href[^>]+>/', '', $string);
	$string = " ".$string;
	$string = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1" rel="nofollow" target="_blank">\\1</a>', $string);
	$string = eregi_replace('(((f|ht){1}tps://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '<a href="\\1" rel="nofollow" target="_blank">\\1</a>', $string);
	$string = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" rel="nofollow" target="_blank">\\2</a>', $string);
	$string = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})', '<a href="mailto:\\1" rel="nofollow" target="_blank">\\1</a>', $string);

	return $string;
}

/* vim: set expandtab: */

?>
